package com.qzsoft.zhjd.warning.modules.warningcementconfig.controller;

import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qzsoft.jeemis.common.utils.Result;
import com.qzsoft.jeemis.common.validator.ValidatorUtils;
import com.qzsoft.jeemis.common.validator.group.AddGroup;
import com.qzsoft.jeemis.common.validator.group.UpdateGroup;
import com.qzsoft.zhjd.common.enums.BizCode;
import com.qzsoft.zhjd.common.utils.RenExceptionUtils;
import com.qzsoft.zhjd.common.utils.ResultUtils;
import com.qzsoft.zhjd.warning.modules.warningcementconfig.dto.WarningCementConfigListDto;
import com.qzsoft.zhjd.warning.modules.warningcementconfig.entity.WarningCementConfigEntity;
import com.qzsoft.zhjd.warning.modules.warningcementconfig.service.WarningCementConfigService;

/**
 * @ClassName WarningCementConfigController
 * @Description 水稳预警设置控制器
 * @author linhuawei
 * @since 2022-05-16
 */
@RestController
@RequestMapping("/api/warningCementConfig")
public class WarningCementConfigController {

    @Autowired
    private WarningCementConfigService warningCementConfigService;

    /**
     * @Title page
     * @Description 查询水稳预警分页列表
     * @param params 查询条件
     * @return 水稳预警分页列表
     */
    @RequiresPermissions("warning:cementconfig:page")
    @GetMapping("/page")
    public Result<IPage<WarningCementConfigListDto>> page(@RequestParam Map<String, Object> params) {
        IPage<WarningCementConfigListDto> page = warningCementConfigService.pageDto(params);
        return ResultUtils.ok(page);
    }

    /**
     * @Title info
     * @Description 获取预警设置对象
     * @param id 预警主键
     * @return 预警设置对象
     */
    @RequiresPermissions("warning:cementconfig:update")
    @GetMapping("/info/{id}")
    public Result<WarningCementConfigEntity> info(@PathVariable String id) {
        WarningCementConfigEntity entity = warningCementConfigService.getInfo(id);
        if (null == entity) {
            RenExceptionUtils.throwEx(BizCode.PARAMS_ERROR, "预警设置不存在");
        }
        return ResultUtils.ok(entity);
    }

    /**
     * @Title save
     * @Description 添加水稳预警设置
     * @param entity 设置信息
     * @return 添加结果
     */
    @RequiresPermissions("warning:cementconfig:save")
    @PostMapping("/save")
    public Result<String> save(@RequestBody WarningCementConfigEntity entity) {
        ValidatorUtils.validateEntity(entity, AddGroup.class);
        warningCementConfigService.save(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title update
     * @Description 修改水稳预警设置
     * @param entity 设置信息
     * @return 修改结果
     */
    @RequiresPermissions("warning:cementconfig:update")
    @PostMapping("/update")
    public Result<String> update(@RequestBody WarningCementConfigEntity entity) {
        ValidatorUtils.validateEntity(entity, UpdateGroup.class);
        warningCementConfigService.updateById(entity);
        return ResultUtils.ok();
    }

    /**
     * @Title delete
     * @Description 删除水稳预警设置
     * @param entity 设置信息
     * @return 删除结果
     */
    @RequiresPermissions("warning:cementconfig:delete")
    @PostMapping("/delete/{id}")
    public Result<String> delete(@PathVariable String id) {
        warningCementConfigService.removeById(id);
        return ResultUtils.ok();
    }

}
